﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace FaultDiagnosisSystem.Controllers
{
    public class LifeAnalysisController : Controller
    {
        // GET: LifeAnalysis
        public ActionResult Index()
        {
            ViewBag.DateSelectList = BuildDateSelect();
            return View();
        }

        /// <summary>
        /// 构建日期下拉菜单
        /// </summary>
        /// <returns></returns>
        private IList<SelectListItem> BuildDateSelect()
        {
            //var lastDayOfRealTime = new BLL.RealTimeFaultDataDaily().GetLastDay();

            var today= DateTime.Today;
            var endDay = today.AddDays(-7);   //向前推7天，作为末尾时间

            var dateSelectList = new List<SelectListItem>();
            dateSelectList.Add(new SelectListItem()
            {
                Text = @"最近一年",
                Value = endDay.ToString("yyyy-MM-dd"),
                Selected = true
            });
            for (int i = DateTime.Today.Year; i > 2016; i--)
            {
                dateSelectList.Add(new SelectListItem() { Text = i.ToString()+@" 年", Value = new DateTime(i,12,31).ToString("yyyy-MM-dd") });
            }

            return dateSelectList;
        }

        public JsonResult GetLastLifeData()
        {
            var list = new BLL.LifeLeft().GetLastLifeData();
            return Json(list, JsonRequestBehavior.AllowGet);
            
        }

        public JsonResult GetCycleLifeData(DateTime day)
        {
            var array = new BLL.LifeLeft().GetCycleLifeDataArray(day);
            return Json(array, JsonRequestBehavior.AllowGet);
        }
    }


}